import request from '@/http/request'

//封装登录请求
export function LoginApi(params) {
    return request({
        url: '/login',
        method: 'POST',
        params
    })
}

//封装左侧列表请求
export function getMenuApi() {
    return request({
        url: '/menus',
    })
}

//封装表格列表请求
export function getTablist(params) {
    return request({
        url: '/users',
        params
    })
}

//封装添加用户列表请求
export function AddLists(data) {
    return request({
        url: '/users',
        method: 'POST',
        data
    })
}

//封装删除用户接口
export function DeleteApi(id) {
    return request({
        url: '/users/' + id,
        method: 'DELETE'
    })
}

//封装修改用户状态接口
export function UpdateStatus(obj) {
    return request({
        url: `users/${obj.uid}/state/${obj.type}`,
        method: 'PUT'
    })
}

//封装编辑用户接口
export function UpdateContent(obj) {
    return request({
        url: `users/${obj.id}`,
        method: 'PUT',
        data: {
            email: obj.email,
            mobile: obj.mobile
        }
    })
}

//分配角色列表
export function getRole() {
    return request({
        url: '/roles',
        method: 'GET'
    })
}

//添加角色列表
export function getRoleData(data) {
    return request({
        url: '/roles',
        method: 'POST',
        data
    })
}

//分配角色权限
export function getRoleAuth(rid, id) {
    return request({
        url: `/users/${rid}/role`,
        method: 'PUT',
        data: { rid: id }
    })
}


//权限列表
export function getAuthorList(type = 'list') {
    return request({
        url: `/rights/${type}`,
        method: 'GET'
    })
}

//编辑提交角色列表
export function setExitData(obj) {
    return request({
        url: `/roles/${obj.id}`,
        method: 'PUT',
        data: {
            roleName: obj.roleName,
            roleDesc: obj.roleDesc
        }
    })
}

//删除角色
export function DeleteData(id) {
    return request({
        url: `/roles/${id}`,
        method: 'DELETE'
    })
}

//角色授权接口
export function setAuthors(obj) {
    return request({
        url: `roles/${obj.id}/rights`,
        method: 'POST',
        data: {
            rids: obj.rids
        }
    })
}

//删除角色指定权限
export function DeleteAuthData(obj) {
    return request({
        url: `roles/${obj.id}/rights/${obj.rid}`,
        method: 'DELETE',
    })
}

//商品列表数据
export function getGoodsData(params) {
    return request({
        url: `goods`,
        method: 'GET',
        params
    })
}

//删除商品列表数据
export function DeleteGoods(id) {
    return request({
        url: `goods/${id}`,
        method: 'DELETE'

    })
}

//商品分类数据列表
export function GoodList(type = 3) {
    return request({
        url: `categories`,
        method: 'GET',
        params: {
            type
        }
    })
}

//添加动态参数或者静态属性接口
export function getGoodsParamsList(id, sel = 'many') {
    return request({
        url: `categories/${id}/attributes`,
        method: 'GET',
        params: {
            sel
        }
    })
}

// 添加商品
export function addGoodsApi(data) {
    return request({
        url: 'goods',
        method: 'POST',
        data
    })
}

// 数据统计
export function reportsApi() {
    return request({
        url: 'reports/type/1',
        method: 'GET'
    })
}
